package br.com.comanda.customadapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import br.com.comanda.R;
import br.com.comanda.vos.Account;

public class AccountAdapter extends ArrayAdapter<Account> {

	/*
	 * Used to instantiate layout XML file into its corresponding View objects
	 */
	private final LayoutInflater inflater;

	/*
	 * each list item layout ID
	 */
	private final int resourceId;

	public AccountAdapter(Context context, int resource, List<Account> objects) {
		super(context, resource, objects);
		this.inflater = LayoutInflater.from(context);
		this.resourceId = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Account account = getItem(position);

		convertView = this.inflater.inflate(this.resourceId, parent, false);

		TextView clientName = (TextView) convertView.findViewById(R.id.tv1);
		TextView board = (TextView) convertView.findViewById(R.id.tv2);
		TextView total = (TextView) convertView.findViewById(R.id.tvTotalValue);

		/*
		 * Button add = (Button) convertView.findViewById(R.id.btnAdd);
		 * 
		 * add.setOnClickListener(new OnClickListener() {
		 * 
		 * public void onClick(View v) { AlertDialog.Builder mensagem = new
		 * AlertDialog.Builder(getContext());
		 * mensagem.setTitle("Adicionar Item " + account.getId());
		 * mensagem.setMessage
		 * ("Abre a tela para inserir um novo item para o cliente " +
		 * account.getClient()); mensagem.setNeutralButton("OK", null);
		 * mensagem.show();
		 * 
		 * } });
		 */
		clientName.setText(account.getClient());
		board.setText(account.getBoard().getBoard());
		total.setText(account.getTotal().toString());

		return convertView;
	}
}
